Money.java

package money;


/**
 * The common interface for simple Monies and MoneyBags
 *
 * @author Kent Beck
 * @author Robert Duvall (small updates and commenting)
 */
public abstract class Money {
    /**
     * Adds given money to this money.
     */
    public abstract Money add (Money m);

    /**
     * Subtracts given money from this money.
     */
    public abstract Money subtract (Money m);

    /**
     * Multiplies this money by the given factor.
     */
    public abstract Money multiply (int factor);

    /**
     * Negates this money.
     */
    public abstract Money negate();

    /**
     * Tests whether this money is zero
     */
    public abstract boolean isZero();

    /**
     * Adds given simple money to this money.
     *
     * This is a non-public helper method for implementing "double dispatch" --- one needed for each different subclass
     */
    abstract Money addMoney (SimpleMoney m);

    /**
     * Adds given MoneyBag to this money.
     *
     * This is a non-public helper method for implementing "double dispatch" --- one needed for each different subclass
     */
    abstract Money addMoneyBag (MoneyBag s);
}